<template>
<div class="box">
<!-- 登录页面负责人王向森 -->
  <div class="b">
    <h2 style="text-align:center">登录</h2>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  <el-form-item label="用户名" prop="username">
    <el-input v-model="ruleForm.username"> <i slot="prefix" class="el-input__icon el-icon-user"></i></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input type="password" v-model="ruleForm.password"> <i slot="prefix" class="el-input__icon el-icon-goods"></i></el-input>
  </el-form-item>
  <el-form-item class="btn">
    <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
  </el-form-item>
    </el-form>
  </div>

</div>
</template>

<script>
import {login} from '@/http/api'
export default {
  name: '',  // 
  
  components: {},//引入子  
  data () {//数据
    return {
      ruleForm:{
        username:'',
        password:''
      }
        
      ,
      rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 3, max:7, message: '长度在 3 到7个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 3, max: 7, message: '长度在 3 到 7 个字符', trigger: 'blur' }
          ],
          }
    }
  },
  created () { },//todo钩子函数 实例创建之前 
  mounted () { },//真实dom挂载之后，运行，这时可以访问dom元素
  methods: {
     submitForm(formName) {
        this.$refs[formName].validate( async (valid) => {
          if (valid) {
             await login(this.ruleForm)
             this.$router.push('/')
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
  },//!事件函数
  computed:{} , //计算属性
  watch:{ //监听属性
   a: {
deep: true,
immediate: true,
handler(newval){},
}
}
}
</script>
<style scoped lang='scss'>
// 登录页面负责人王向森
.box{
  width: 100%;height: 100vh;
  background-color: rgb(25, 21, 93);
  position: relative;
}
.b{
  background-color: #fff;
  padding:30px 30px 30px 0;
  // text-align: center;
  width: 25%;
  height: 250px;
  min-width: 400px;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
 bottom: 0;
  margin: auto;
     border-radius: 10px;
    box-shadow: 0px 0px 10px #fff;
    h2{
      text-align: center;
    }
}
.btn{
  text-align: right;
}
</style>
